<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <!-- Favicons -->
    <link rel="icon" type="image/x-icon" href="/assets/images/favicon.ico" />
    <link rel="icon" type="image/png" sizes="32x32" href="/assets/images/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/assets/images/favicon-16x16.png" />
    <link rel="icon" type="image/svg+xml" href="/assets/images/logo-symbol.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Terrateam</title>
    
    <!-- Environment Configuration -->
    <script nonce="NGINX_CSP_NONCE">
      // Inject environment configuration from server/build process
      window.terrateamConfig = {
        ui_analytics: '%TERRATEAM_UI_ANALYTICS%',
        ui_subscription: '%TERRATEAM_UI_SUBSCRIPTION%',
        maintenanceMode: '%TERRATEAM_MAINTENANCE%',
        maintenanceMessage: '%TERRATEAM_MAINTENANCE_MESSAGE%',
        upgrade_nudges: '%TERRATEAM_UPGRADE_NUDGES%'
      };
      
      // Handle template replacement fallbacks for development
      Object.keys(window.terrateamConfig).forEach(key => {
        const value = window.terrateamConfig[key];
        if (value && typeof value === 'string' && value.startsWith('%') && value.endsWith('%')) {
          // Template replacement didn't happen - set development defaults
          switch(key) {
            case 'ui_analytics':
              window.terrateamConfig[key] = 'disabled'; // Default to disabled for safety
              break;
            case 'ui_subscription':
              window.terrateamConfig[key] = 'oss'; // Default to OSS mode
              break;
            case 'maintenanceMode':
              window.terrateamConfig[key] = 'false'; // Default to not in maintenance
              break;
            case 'maintenanceMessage':
              window.terrateamConfig[key] = ''; // Default to empty message
              break;
            case 'upgrade_nudges':
              window.terrateamConfig[key] = 'false'; // Default to disabled
              break;
          }
        }
      });
      
    </script>
    
    <!-- Reddit Pixel (only loads when analytics are enabled) -->
    <script nonce="NGINX_CSP_NONCE">
    // Only initialize Reddit Pixel if analytics are enabled
    if (window.terrateamConfig && window.terrateamConfig.ui_analytics === 'enabled') {
      !function(w,d){if(!w.rdt){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments)};p.callQueue=[];var t=d.createElement("script");t.src="https://www.redditstatic.com/ads/pixel.js",t.async=!0;var s=d.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}}(window,document);
      rdt('init','a2_goli51v33nfp');
      rdt('track', 'PageVisit');
    }
    </script>
    <!-- DO NOT MODIFY UNLESS TO REPLACE A USER IDENTIFIER -->
    <!-- End Reddit Pixel -->
    
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>
